home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8165 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: more problems with qsort
  5. Date: 2 Mar 1996 02:31:41 GMT
  6. Organization: Nando.net Public Access
  7. Message-ID: <4h8bud$1vd@castle.nando.net>
  8. References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: vyger117.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4h0j9e$ng5@clarknet.clark.net>,
  14. yom@clark.net (yom) writes:
  15.  
  16. >Since you're trying to sort a char**, the qsort function call must
  17. >look like this:
  18. >
  19. >qsort(array,lines,sizeof(char **),(int (*)(void *,void *)) compare);
  20. >
  21. >And your compare function must be defined like this:
  22. >
  23. >int compare(char **a,char **b) {return strcmp(*a,*b);}
  24.  
  25. Didn't you mean to type "sizeof( char * )" which, IMHO, could be
  26. better expressed as "sizeof array[0]" ?  Also, there's no need to
  27. further complicate the call of qsort with the cast on compare if
  28. you define compare() as:
  29.  
  30. int compare( const void *a, const void *b )
  31. {
  32.    return strcmp( *(const char **)a, *(const char **)b );
  33. }
  34.  
  35. Bill McCarthy
  36. actuary@nando.net
  37. Wendell, NC  USA
  38.